package com.lovo.gui.Ddz;


import java.awt.Point;

public class CMoving {
    public static void move(BCards cards, Point start, Point end) {
        if (start.x != end.x) {
            // 默认向左移动
            int speed = -10;
            if (start.x < end.x) {
                // 向右边移动
                speed = -speed;
            }
            double tangent = ((double) end.y - start.y) / Math.abs(end.x - start.x);
            while (Math.abs(end.x - start.x) > 20) {
                start.x += speed;
                start.y += Math.abs(speed) * tangent;
                cards.setLocation(start.x, start.y);
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            // 最后校准位置
            cards.setLocation(end);
        }
    }
}